#ifndef __XZ_F31_API_H__
#define __XZ_F31_API_H__
#endif

extern "C"
{
// 打开串口
int SUNSON_OpenCom(const char * sztty, long nBaudrate);
// 关闭串口
int SUNSON_CloseCom(void);
// 从串口读取一个字节的内容，获取按下的按键键值
int SUNSON_ScanKeyPress(unsigned char *ucValue);
int SUNSON_ScanGetKey(unsigned char *ucValue); // 被动模式获取键值，发送指令从键盘读取键值
// 获取操作执行后的错误信息或成功标志信息
int SUNSON_GetOperationResult(unsigned char *ucResultInfo);

// B.1 取EPP键盘版本号
int SUNSON_GetVersionNo(unsigned char*VersionNo);
// B.2 键盘复位
int SUNSON_ResetEpp(unsigned char *ReturnInfo);
// B.3 设置按键属性（屏蔽、激活、终止）
int SUNSON_SetKeyMark(long ActiveFunc,long ActiveFDK,long EndFunc,long EndFDK,unsigned char*ReturnInfo);
// B.4 读取密钥校验值
int SUNSON_GetCheckValue(unsigned char ucCheckMode,unsigned char *CheckValue);
// B.5 下载用户密钥
int SUNSON_LoadUserKey(int ucKeyId,int ucDecryptKeyId,unsigned char  KeyAttribute,unsigned char ucKeyLen,unsigned char *KeyValue,unsigned char *ReturnInfo);
// B.6 删除所有密钥
int SUNSON_DeleteAllKeys(unsigned char *ReturnInfo);  
// B.7 删除指定的用户密钥
int SUNSON_DelSpecialUserKey(int UserKeyId,unsigned char *ReturnInfo);
// B.8 设置蜂鸣器
int SUNSON_SetBuzzerEnabled(unsigned char ucBuzzerStatus,unsigned char *ReturnInfo);
// B.9 设置MAC初始向量
int SUNSON_SetStartValue(unsigned char *StartValue,unsigned char *ReturnInfo);
int SUNSON_SetStartValueEx(int nDataLen,unsigned char *StartValue,unsigned char *ReturnInfo);
// B.10 数据运算
int SUNSON_DataCompute(int KeyId,unsigned char JM_mode,unsigned char SF_mode,unsigned char padchar,int datalen,unsigned char *data,unsigned char *DataResult);
// B.11 开始PIN操作（执行后可以输入密码）
int SUNSON_GetPin(unsigned char ucPinMinLen,unsigned char ucPinMaxLen,unsigned char AutoReturnFlag,unsigned char *ReturnInfo);
// B.12 PINBLOCK运算
int SUNSON_GetPinBlock(int UserKeyId,int JM_mode,unsigned char padchar,unsigned char ucCardLen,unsigned char*ucCardNumber,unsigned char*PinBlockResult);
// B.13 MAC运算
int SUNSON_MakeMac(int UserKeyId,int Mac_mode,int nMacDataLen,unsigned char *ucMacData,unsigned char *MacResult);
// B.14 打开EPP仿真键盘（使键盘可以输出明文）
int SUNSON_UseEppPlainTextMode(unsigned char PlaintextLength,unsigned char AutoEnd,unsigned char *ReturnInfo);
// B.15 关闭EPP键盘
int SUNSON_CloseEppPlainTextMode(unsigned char *ReturnInfo);
// B.16 取随机数
int SUNSON_GetRandomData(unsigned char ucRandomDataType,unsigned char ucDataLength,unsigned char *ReturnInfo);

//  UBC算法
int SUNSON_MakeUBCMac(int UserKeyId,int nMacLen,unsigned char* macdata,unsigned char *ReturnInfo);

//  获取键盘状态
int SUNSON_GetEppStatus(unsigned char*EppStatus);
//  设置卡键时间
int SUNSON_SetLockKeyTimeOut(unsigned char TimeOut,unsigned char *ReturnInfo);

// 打开/关闭开封自毁   0x00 关闭固件自毁(仅100N支持)
//                      0x01 开启固件自毁(仅100N支持)
//                      0x02 关闭密钥自毁
//                      0x04 开启密钥自毁
int SUNSON_EnableMoveDestruct(unsigned char mode, unsigned char *ReturnInfo);

// 国密相关
// 设置国密非密模式
int SUNSON_SetEPPSMMode(unsigned char ucSMMode);
// 获取键盘模式
int SUNSON_GetEPPSMMode(unsigned char *ucEPPMode);
//  生成SM2密钥
int SUNSON_GenerateSM2Key(int ucKeyId,int KeyAtt,unsigned char *ReturnInfo);
//  下载SM2密钥
int SUNSON_LoadSM2Key(int ucKeyId,int KeyAtt,int nKeylen,unsigned char *KeyValue,unsigned char *ReturnInfo);
// 导出SM2公钥
int SUNSON_ExportSM2PublicKey(int ucKeyId,unsigned char *ReturnInfo);
// Hash ID初始化
int SUNSON_InitHashID(int ucKeyId,unsigned char UserIDLen,unsigned char *UserID,unsigned char *ReturnInfo);
// SM2签名
int SUNSON_GetSM2SignatureEX(int ucKeyId,unsigned char EDataLen,unsigned char *EData,unsigned char *ReturnInfo);
// SM2验签
int SUNSON_VerifySM2SignatureEX(int ucKeyId,unsigned char EDataLen,unsigned char *EData,unsigned char SignatureLen,unsigned char *Signature,unsigned char *ReturnInfo);
// SM2数据运算
int SUNSON_SM2DataCompute(int ucKeyId,unsigned char ucKeyType,int nDatalen,unsigned char *data,unsigned char *DataResult);
// SM3哈希操作
int SUNSON_SM3HashOperateEX(unsigned char ucSM3HashType,int nDatalen,unsigned char *data,unsigned char *DataResult);
// 使能国密程序下载
int SUNSON_EnableLoadSMFirmware(void);

// 导入SM4密钥，通过SM2解密
int SUNSON_ImportSM4KeyUseSM2key(int nSM2keyID, int nSM4keyID, int nKeyAttr, int nKeyLen, unsigned char* KeyValue, unsigned char* ReturnInfo);


// 设置能否重复下载密钥 00 允许重复下载； 01 不允许重复下载
int SUNSON_EnableLoadSameKey(unsigned char Mode, unsigned char *ReturnInfo);

// 获取指定密钥的KCV
int SUNSON_GetKCV(int keyId, unsigned char ucCheckMode,unsigned char *CheckValue);

// 获取密钥属性值
int SUNSON_GetKeyAttInfo(int UserKeyId, unsigned char *KeyAttInfo);

// 设置波特率 mode 0x30 2400:
// 0x31 4800:
// 0x32 9600
// 0x33 19200
// 0x34 38400
// 0x35 57600
// 0x36 115200
int SUNSON_SetBaudRate(unsigned char ucBaudRateMode,unsigned char *ReturnInfo);

// 开关usb明文系统键盘  0x01关闭USB系统键盘
// 0x02开启USB系统键盘                      
int SUNSON_EnableUSBplaintext(unsigned char mode);

// 开关日志  0-关闭日志；1-打开日志
void SUNSON_OpenLog(int nFlag);
// 开关日志，设置日志级别
// bFlag, 0关闭日志，1 打开日志
// nLogLevel, 0不带敏感信息（卡号、pinblock数据）；1-带敏感数据
void SUNSON_OpenLogEx(unsigned char bFlag, int nLogLevel);

// RSA
// 导出RSA公钥
int SUNSON_ExportRSAKey(unsigned char ucKeyId, unsigned char *ucData);
// 导入RSA密钥
int SUNSON_LoadRSAKey(unsigned char ucKeyId,unsigned char nSignatureId, int nKeylen, unsigned char *KeyValue, int nSignatureLen, unsigned char* SignatureData, unsigned char * ReturnInfo);
// RSA签名
int SUNSON_GetRSASignature(unsigned char ucKeyId, unsigned char Padding,unsigned char HashId,int DataLen,
									unsigned char *ucData,unsigned char *DataResult);
// RSA验签
int SUNSON_VerifyRSASignature(unsigned char ucKeyId, unsigned char Padding,unsigned char HashId,int SignLen,
										unsigned char *SignData,int DataLen,unsigned char *ucData,unsigned char *ReturnInfo);

// RSA导出签名DER格式（部分键盘支持）
int SUNSON_ExportRSASignDer(unsigned char ucKeyId, unsigned char SignkeyId, unsigned long SignAlg, unsigned char *ucData);

// 导入无签名的RSAKEY KeyType = 0x01 导DER私钥
//                    KeyType = 0x02 导DER公钥
int SUNSON_ImportNoSignRSAKey(unsigned char ucKeyId, unsigned char KeyType, int DataLen,unsigned char *ucData,unsigned char *ReturnInfo);

// RKL 接口	
// 生成RSA密钥 nKeylen 1024,2048 exp 3, 17, 65537
int SUNSON_GenerateRSAKey(unsigned char ucKeyId, long nKeylen,long Eval, long Dwuse, unsigned char* ReturnInfo);
// 导出RSA DerKey mode:0x01 DER格式, 0x02:256字节N值
int SUNSON_ExportRSADerKey(unsigned char ucKeyId, unsigned char mode, int *nkeyderLen, unsigned char *ucKeyDer, int *nSignLen, unsigned char *ucSignData, unsigned char* ReturnInfo);
// 导入RSA DerKey
int SUNSON_ImportRSADerKey(unsigned char ucKeyId, unsigned char SignkeyId, int DerKeyLen, unsigned char *DerKey, long Dwuse, 
									long SignAlg, long CheckMode, int SignLen, unsigned char *SignDat, unsigned char *ucResult);
// 导入签名值
int SUNSON_ImportSignValue(unsigned char nKeyId, int SignLen, unsigned char * SignData, unsigned char *ReturnInfo);
// 导入RSA签名的DES密钥
int SUNSON_ImportRSADesKey(unsigned char nDESKeyId, unsigned char nRSAKeyId, unsigned char SignKeyId, long EncipherAlg, long SignAlg, long Dwuse,
									int LpxValLen, unsigned char *LpxVal, int LpxSignLen, unsigned char *LpxSign, unsigned char *ucResult);
// 导入RSAdes密钥分量
//  KeyLenMode,  0x01, 8字节密钥分量，
//               0x02, 16字节密钥分量,
//               0x03, 24字节密钥分量
//  KcvLenMode,  0x01, 密钥分量校验值长8字节
//               0x02, 密钥分量校验值长16字节
//               0x03, 密钥分量校验值长24字节
//  KeyCountMode 0x01, 1个密钥分量
//               0x02, 2个密钥分量
//               0x03, 3个密钥分量
//  nSignKeyId   ,0-11,0xff 不需要验签
//  EncipherAlg    "解密填充算法。
// 0x01 – LTC_LTC_PKCS_1_V1_5
// 0x02 – LTC_LTC_PKCS_1_OAEP
//  SignAlg：签名填充算法
//  0x01 – LTC_LTC_PKCS_1_V1_5
// 0x03 - LTC_LTC_PKCS_1_PSS
int SUNSON_ImportRSADesKeyEx(unsigned char KeyLenMode, unsigned char KcvLenMode, unsigned char KeyCountMode, unsigned char nDESkeyid, unsigned char nRsaKeyId, unsigned char nSignKeyId, long 						EncipherAlg, long SignAlg, long dwUse,
	                  int LpxValLen, unsigned char *LpxVal, int LpxSignLen, unsigned char *LpxSign, unsigned char *ucResult);

// 导入EPPID和签名值 signAlg 签名算法
int SUNSON_ImportEppidAndSignData(unsigned char SignAlg, int nEppidLen, unsigned char *EPPID, int SignLen, unsigned char *SignData, unsigned char* ReturnInfo);

// 导出EPPID和签名值
int SUNSON_ExportEppidAndSignData(unsigned char *SignAlg, int *nEppidLen, unsigned char *EPPID, int *SignLen, unsigned char *SignData, unsigned char* ReturnInfo);

// RSA运算
int SUNSON_RSACompute(int KeyId,unsigned char keyClass, unsigned char PaddingMode,
									unsigned char HashMode,int datalen,unsigned char *data,unsigned char *DataResult);

// 导出EPP键盘签名和指定密钥签名的EPPID
int SUNSON_ExportEPPsignEPPid(int SignKeyID, unsigned char SignAlgorithm, int *nEppidLen, unsigned char *EPPID, int *SignLen, unsigned char *SignData, unsigned char* ReturnInfo);

// 导出EPP键盘签名和指定密钥签名的公钥数据
int SUNSON_ExportEPPsignPublicKey(int keyID, int SignKeyID, unsigned char SignAlgorithm, int *PublicKeyLen, unsigned char* PublicKey,int *EppPrivatekeySignLen, unsigned char *EppPrivatekeySignData, int *SignLen, unsigned char *SignData, unsigned char* ReturnInfo);

// 设置RKL hash算法 0:NID_MD5, 1:NID_sha1, 2:NID_sha224, 3:NID_sha256
int SUNSON_SetHashMode(int nMode, unsigned char* ReturnInfo);

// 获取SM2公钥的SM3 KCV值
int SUNSON_GetSM2keySM3kcv(int nSM2keyid, unsigned char* KCV);
// 导入SM2公钥
int SUNSON_ImportSM2publickey(int nSm2keyid, int nSignKeyid, int nKeyDatalen, unsigned char * KeyData, int nSM2keyattr, int nSignAlg, int nSignDatalen, unsigned char* SignData, unsigned char* ReturnInfo);
// 导入带SM2签名的SM2加密的SM4密钥
int SUNSON_ImportSM4KeyUseSM2keySign(int nSM4keyid, int nSM2keyid, int nSignKeyid, int DecryptAlg, int SignALg, long nKeyAttr, int nDatalen, unsigned char*Data, int nSignLen, unsigned char* SignData, unsigned char* ReturnInfo);
// 导出SM2公钥签名
int SUNSON_ExportSM2publickeySignData(int nSM2keyid, unsigned char* SignData);
// 导入SM2公钥签名
int SUNSON_ImportSM2publickeySignData(int nSM2keyid, int nSignlen, unsigned char* SignData, unsigned char* ReturnInfo);
// 设置签名者ID
int SUNSON_SetSignUserID(int nUserIDLen, unsigned char *UserID, unsigned char* ReturnInfo);

// 导出SM2的EPPID和签名值 
int SUNSON_ExportSM2EppidAndSignData(unsigned char *SignAlg, int *nEppidLen, unsigned char *EPPID, int *SignLen, unsigned char *SignData, unsigned char* ReturnInfo);

// 获取键盘序列号
int SUNSON_ReadSN(unsigned char*SerialNumber);

// 新增与F35相同的接口，方便开发调用代码保持一致
// 1.45 切换算法 0x00 DES/3DES ; 0x02 SM4
int SUNSON_SwitchArithmetic(unsigned char ArithmeticType,unsigned char *DataResult);
// 设置卡键时间
int SUNSON_SetStuckKeyTimeOut(unsigned char TimeOut,unsigned char *ReturnInfo);
// 获取键盘固件版本
int SUNSON_GetFirmwareVer(unsigned char *ucFirmwareVer);
// // 1.39 SM2签名
int SUNSON_GetSM2Signature(int ucKeyId,unsigned char OpenFlag,
		int EDataLen,unsigned char *EData,unsigned char *ReturnInfo);
// // 1.40 SM2验签
int SUNSON_VerifySM2Signature(int ucKeyId,unsigned char OpenFlag,int SignatureLen,
		unsigned char *Signature,int EDataLen,unsigned char *EData,unsigned char *ReturnInfo);
// 1.42 SM3哈希操作
int SUNSON_SM3HashOperate(unsigned char ucSM3HashType,unsigned char OperateFlag,
		int nDatalen,unsigned char *data,unsigned char *DataResult);
// 1.43 下载SM4密钥
int SUNSON_LoadSM4Key(int ucKeyId,int ucDecryptKeyId,int KeyAttribute,unsigned char ucKeyLen,unsigned char *KeyValue,unsigned char *ReturnInfo);

// USB键盘使能 系统键盘功能 ,0 关闭，1打开
int SUNSON_EnableSystemKeyboard(unsigned char nFlag,unsigned char *ReturnInfo);
// 民生银行版本接口 设置设备信息
// nType  0x30:厂商信息  最大10个字符
//        0x31:EPP信息   最大20个字符
//        0x32:键盘序列号  最大30个字符
//        0x33:驱动库名称  最大30个字符
int SUNSON_SetDeviceInfo(int nType, unsigned char* InfoData);
// 民生银行版本指令 读取设备信息
int SUNSON_GetDeviceInfo(unsigned char* DevName, unsigned char* EppName, unsigned char* EppNo, unsigned char* DriName);

}
